<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MemberLogin extends CI_Controller {
	
	 public function __construct()
	    {
	        parent::__construct();
	        session_start();
	        $this->output->enable_profiler(FALSE);
	    }
	    
	public function index()
	{
		$data['title'] = "Welcome to Norton";
		$this->load->vars($data);
		$this->load->view('template');
	}
	
	
	public function setting() {
		if (!isset($_SESSION['uid']) || $_SESSION['uid'] < 1){
		   	redirect('memberlogin/requiredmessage','refresh');
		}
		
		if ($this->input->post('submit')){
	  		if($_SESSION['role_id']==1) {	
                $this->MStaff->updateStaff();
                $this->session->set_flashdata('message','Account updated');
	  			redirect('hradmin','refresh');
			}
	  		elseif($_SESSION['role_id']==2) {	
	  		    $this->MStaff->updateAccountSetting();
                $this->session->set_flashdata('message','Account updated');
				redirect('employee','refresh');
			}
	  		
	  	}else{
			$data['title'] = "Account Setting";
			$data['main'] = 'account_form_setting';
			$data['roles'] = $this->MUser->getRoles();
			$data['status'] = $this->MStaff->getStatusDropdown();
			$data['positions'] = $this->MPosition->getPositionDropdown();	
			$data['teams'] = $this->MTeam->getTeamDropdown();
			$data['staff'] = $this->MStaff->getAccountDetailByUId($_SESSION['uid']);	
        	if($_SESSION['role_id']==1) {			
                $data['locations'] = $this->MStaff->getLocationDropDown();
                $data['lastSID'] = $this->MStaff->getLastSID(0,1);
  			    $data['form'] = $this->MFormGlobal->getFormSaveCancelBottom('/index.php/hradmin');
			}
	  		elseif($_SESSION['role_id']==2) {	
				$data['form'] = $this->MFormGlobal->getFormSaveCancelBottom('/index.php/employee');
			}
			$this->load->vars($data);
			$this->load->view('template');   
		}
	}
	
	public function login() {
		if ($this->input->post('username')){
			$u = $this->input->post('username');
			$pw = $this->input->post('password');
			$this->MUser->verifyUser($u,$pw);
			if ($_SESSION['uid'] > 0){
				if($_SESSION['role_id']==1) {
					redirect('hradmin','refresh');
				}
				else if ($_SESSION['role_id']== 2){
					//redirect('employee','refresh');
                    redirect('memberlogin/setting','refresh');
				}
			}
		}
		$data['title'] = "Human Resource Management System for Friends-International Organization";
		$data['main'] = 'login';
		$this->load->vars($data);
		$this->load->view('template');  
	}
	
	function logout(){
		unset($_SESSION['uid']);
		unset($_SESSION['role_id']);
		unset($_SESSION['username']);
		$this->session->set_flashdata('error',"You've been logged out!");
		redirect(base_url(),'refresh'); 	
	 }
	 
	 function requiredmessage() {
	 	$data['title'] = "Require Login";
		$data['main'] = 'requiredlogin';
		$this->load->vars($data);
		$this->load->view('template','refresh');  
	 }
	 
	 function restriction() {
	 	$data['title'] = "Restricted Access";
		$data['main'] = 'restriction';
		$this->load->vars($data);
		$this->load->view('template','refresh');  
	 }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */